package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.placeType.PlaceTypeTreeDto;
import com.lnking.lnkingplace.model.request.placeType.PlaceTypeAddRequest;
import com.lnking.lnkingplace.model.request.placeType.PlaceTypeUpdateRequest;
import com.lnking.lnkingplace.service.IPlaceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/place-type")
@Api(tags = "场所类型")
public class PlaceTypeController {

    @Resource
    IPlaceTypeService placeTypeService;

    @GetMapping("get-tree")
    @ApiOperation("树形列表")
    public ReturnResult getTree(){
        List<PlaceTypeTreeDto> tree = placeTypeService.getTree();
        return ReturnResult.success(tree);
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public ReturnResult add(@RequestBody PlaceTypeAddRequest params){
        placeTypeService.add(params);
        return ReturnResult.success();
    }

    @PostMapping("update")
    @ApiOperation("修改")
    public ReturnResult update(@RequestBody PlaceTypeUpdateRequest params){
        placeTypeService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult update(@PathVariable("id") String id){
        placeTypeService.delete(id);
        return ReturnResult.success();
    }

    @GetMapping("get-info/{id}")
    @ApiOperation("得到该类型的附加信息")
    public ReturnResult getInfo(@PathVariable("id") String id){
        return ReturnResult.success(placeTypeService.getBaseMapper().selectById(id));
    }
}
